package com.izhar.answeringmachine.service.Impl;

import com.izhar.answeringmachine.Entity.Sample;
import com.izhar.answeringmachine.Entity.SubmitCode;
import com.izhar.answeringmachine.mapper.SampleMapper;
import com.izhar.answeringmachine.mapper.SubmitCodeMapper;
import com.izhar.answeringmachine.service.ICheckCodeService;
import com.izhar.answeringmachine.utils.ResultData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class CheckCodeImpl implements ICheckCodeService {

    @Autowired
    SubmitCodeMapper submitCodeMapper;

    @Autowired
    SampleMapper sampleMapper;

    @Override
    public ResultData selectSubmitCode(String id) {

        SubmitCode submitCode = submitCodeMapper.selectById(id);
        if (submitCode==null) {
            throw new RuntimeException("User submit code is null");
        }

        return new ResultData("200","success",submitCode);
    }



    @Override
    public List<Sample> selectParameters(String questionId) {

        List<Sample> samples = sampleMapper.selectByQuestionId(questionId);


        if (samples==null || samples.size()==0) {
            throw new RuntimeException("samples is null or not exist");
        }

        return samples;
    }
}
